From 794776640b50265e2696d4d3be0b8392d3c1c1d1 Mon Sep 17 00:00:00 2001 From: Hans Breuer Date: Sun, 8 Aug 2004 22:31:12 +0000 Subject: [PATCH] take targets into account again to allow dnd of other things than text 2004-08-07 Hans Breuer * gtk/gtkdnd.c (gtk_drag_dest_set) : take targets into account again to allow dnd of other things than text * gdk/win32/gdkselection-win32.c : offer windows bitmap to be pasted from clipboard (makes The GIMP 2.1's "File/Acquire/Paste as New" work, only using gtk+ API) --- ChangeLog | 9 +++ ChangeLog.pre-2-10 | 9 +++ ChangeLog.pre-2-6 | 9 +++ ChangeLog.pre-2-8 | 9 +++ gdk/win32/gdkselection-win32.c | 113 ++++++++++++++++++++++++++++++++- gtk/gtkdnd.c | 5 +- 6 files changed, 149 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c7164852f..078e83cd5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-08-08 Hans Breuer + + * gtk/gtkdnd.c (gtk_drag_dest_set) : take targets into + account again to allow dnd of other things than text + + * gdk/win32/gdkselection-win32.c : offer windows bitmap to + be pasted from clipboard (makes The GIMP 2.1's + "File/Acquire/Paste as New" work, only using gtk+ API) + Sun Aug 8 01:32:36 2004 Matthias Clasen * gtk/gtk.def: Add gtk_cell_renderer_progress_get_type. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 1c7164852f..078e83cd5f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +2004-08-08 Hans Breuer + + * gtk/gtkdnd.c (gtk_drag_dest_set) : take targets into + account again to allow dnd of other things than text + + * gdk/win32/gdkselection-win32.c : offer windows bitmap to + be pasted from clipboard (makes The GIMP 2.1's + "File/Acquire/Paste as New" work, only using gtk+ API) + Sun Aug 8 01:32:36 2004 Matthias Clasen * gtk/gtk.def: Add gtk_cell_renderer_progress_get_type. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 1c7164852f..078e83cd5f 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +2004-08-08 Hans Breuer + + * gtk/gtkdnd.c (gtk_drag_dest_set) : take targets into + account again to allow dnd of other things than text + + * gdk/win32/gdkselection-win32.c : offer windows bitmap to + be pasted from clipboard (makes The GIMP 2.1's + "File/Acquire/Paste as New" work, only using gtk+ API) + Sun Aug 8 01:32:36 2004 Matthias Clasen * gtk/gtk.def: Add gtk_cell_renderer_progress_get_type. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 1c7164852f..078e83cd5f 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +2004-08-08 Hans Breuer + + * gtk/gtkdnd.c (gtk_drag_dest_set) : take targets into + account again to allow dnd of other things than text + + * gdk/win32/gdkselection-win32.c : offer windows bitmap to + be pasted from clipboard (makes The GIMP 2.1's + "File/Acquire/Paste as New" work, only using gtk+ API) + Sun Aug 8 01:32:36 2004 Matthias Clasen * gtk/gtk.def: Add gtk_cell_renderer_progress_get_type. diff --git a/gdk/win32/gdkselection-win32.c b/gdk/win32/gdkselection-win32.c index 5c9e81ca23..63fff2f685 100644 --- a/gdk/win32/gdkselection-win32.c +++ b/gdk/win32/gdkselection-win32.c @@ -369,7 +369,38 @@ gdk_selection_convert (GdkWindow *requestor, _gdk_selection_property_store (requestor, GDK_SELECTION_TYPE_ATOM, 32, (guchar *) data, 1 * sizeof (GdkAtom)); } - else + else if (IsClipboardFormatAvailable (CF_BITMAP) || + IsClipboardFormatAvailable (CF_DIB)) + { + GdkAtom *data = g_new (GdkAtom, 1); + GdkAtom atom = gdk_atom_intern ("image/bmp", FALSE); + *data = atom; + _gdk_selection_property_store (requestor, GDK_SELECTION_TYPE_ATOM, + 32, (guchar *) data, 1 * sizeof (GdkAtom)); + } + else if (CountClipboardFormats() > 0) + { + /* if there is anything else in the clipboard, enum it all although we don't + * offer special conversion services + */ + int fmt = 0, i = 0; + GdkAtom *data = g_new (GdkAtom, CountClipboardFormats()); + + for ( ; 0 != (fmt = EnumClipboardFormats (fmt)); ) + { + char sFormat[80]; + + if (GetClipboardFormatName (fmt, sFormat, 80) > 0) + { + GdkAtom atom = gdk_atom_intern (sFormat, FALSE); + data[i] = atom; + i++; + } + } + _gdk_selection_property_store (requestor, GDK_SELECTION_TYPE_ATOM, + 32, (guchar *) data, i * sizeof (GdkAtom)); + } + else property = GDK_NONE; API_CALL (CloseClipboard, ()); @@ -514,6 +545,86 @@ gdk_selection_convert (GdkWindow *requestor, API_CALL (CloseClipboard, ()); } + else if (selection == GDK_SELECTION_CLIPBOARD && + target == gdk_atom_intern ("image/bmp", TRUE)) + { + if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor)))) + return; + if ((hdata = GetClipboardData (CF_DIB)) != NULL) + { + BITMAPINFOHEADER *ptr; + guchar *data; + + if ((ptr = GlobalLock (hdata)) != NULL) + { + BITMAPFILEHEADER *hdr; /* need to add a file header so gdk-pixbuf can load it */ + gint length = GlobalSize (hdata) + sizeof(BITMAPFILEHEADER); + + GDK_NOTE (DND, g_print ("...BITMAP: %d bytes\n", length)); + + data = g_try_malloc (length); + if (data) + { + hdr = (BITMAPFILEHEADER *)data; + hdr->bfType = 0x4d42; /* 0x42 = "B" 0x4d = "M" */ + /* Compute the size of the entire file. */ + hdr->bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + + ptr->biSize + ptr->biClrUsed + * sizeof(RGBQUAD) + ptr->biSizeImage); + hdr->bfReserved1 = 0; + hdr->bfReserved2 = 0; + /* Compute the offset to the array of color indices. */ + hdr->bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + + ptr->biSize + ptr->biClrUsed * sizeof (RGBQUAD); + /* copy the data behind it */ + memcpy (data + sizeof(BITMAPFILEHEADER), ptr, length - sizeof(BITMAPFILEHEADER)); + _gdk_selection_property_store (requestor, target, 8, + data, length); + } + GlobalUnlock (hdata); + } + + } + + API_CALL (CloseClipboard, ()); + } + else if (selection == GDK_SELECTION_CLIPBOARD) + { + const char *targetname = gdk_atom_name (target); + UINT fmt = 0; + + if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor)))) + return; + /* check if its available */ + for ( ; 0 != (fmt = EnumClipboardFormats (fmt)); ) + { + char sFormat[80]; + + if (GetClipboardFormatName (fmt, sFormat, 80) > 0 && + strcmp (sFormat, targetname) == 0) + { + if ((hdata = GetClipboardData (fmt)) != NULL) + { + /* simply get it without conversion */ + guchar *ptr; + gint length; + + if ((ptr = GlobalLock (hdata)) != NULL) + { + length = GlobalSize (hdata); + + GDK_NOTE (DND, g_print ("... %s: %d bytes\n", targetname, length)); + + _gdk_selection_property_store (requestor, target, 8, + g_memdup (ptr, length), length); + GlobalUnlock (hdata); + break; + } + } + } + } + API_CALL (CloseClipboard, ()); + } else if (selection == _gdk_win32_dropfiles) { /* This means he wants the names of the dropped files. diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index 92075e6326..0f32280ba4 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -2095,10 +2095,7 @@ gtk_drag_source_set (GtkWidget *widget, site->start_button_mask = start_button_mask; - if (targets) - site->target_list = gtk_target_list_new (targets, n_targets); - else - site->target_list = NULL; + site->target_list = gtk_target_list_new (targets, n_targets); site->actions = actions; } -- 2.30.2